package xyz.fivefaith.cloud.common.redis.handler;

import com.baomidou.lock.exception.LockFailureException;

import jakarta.servlet.http.HttpServletRequest;

import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import xyz.fivefaith.tool.common.domain.base.Result;
import xyz.fivefaith.tool.common.domain.enums.ResultCode;

/**
 * Redis异常处理器
 *
 * @author AprilWind
 */
@Slf4j
@RestControllerAdvice
public class RedisExceptionHandler {

    /** 分布式锁Lock4j异常 */
    @ExceptionHandler(LockFailureException.class)
    public Result<Void> handleLockFailureException(
            LockFailureException e, HttpServletRequest request) {
        String requestUri = request.getRequestURI();
        log.error("获取锁失败了'{}',发生Lock4j异常.", requestUri, e);
        return Result.fail(ResultCode.UN_AUTHORIZED.getCode(), "业务处理中，请稍后再试...");
    }
}
